package top.continew.admin.business.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;

import org.springframework.stereotype.Service;

import top.continew.admin.business.mapper.SpecificationTypeMapper;
import top.continew.admin.business.model.entity.SpecificationTypeDO;
import top.continew.admin.business.model.query.SpecificationTypeQuery;
import top.continew.admin.business.model.req.SpecificationTypeReq;
import top.continew.admin.business.model.resp.SpecificationTypeDetailResp;
import top.continew.admin.business.model.resp.SpecificationTypeResp;
import top.continew.admin.business.service.SpecificationTypeService;
import top.continew.starter.extension.crud.service.BaseServiceImpl;

import java.util.List;

/**
 * 规格类型业务实现
 *
 * @author sheng_chao
 * @since 2025/03/04 20:47
 */
@Service
@RequiredArgsConstructor
public class SpecificationSpecificationTypeServiceImpl extends BaseServiceImpl<SpecificationTypeMapper, SpecificationTypeDO, SpecificationTypeResp, SpecificationTypeDetailResp, SpecificationTypeQuery, SpecificationTypeReq> implements SpecificationTypeService {

    @Override
    public Long create(SpecificationTypeReq req) {
        if (req.getParentId() != 0) {
            SpecificationTypeDO specificationTypeDO = this.baseMapper.selectById(req.getParentId());
            if (StrUtil.isNotEmpty(specificationTypeDO.getPath())) {
                req.setPath(specificationTypeDO.getPath() + "/" + req.getParentId());
            } else {
                req.setPath(String.valueOf(req.getParentId()));
            }
        } else {
            req.setPath("");
        }
        return super.create(req);
    }

    @Override
    public List<SpecificationTypeResp> listByQuery(SpecificationTypeQuery query) {
        return baseMapper.selectByQuery(query);
    }
}